var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    needFix:false,
    bannerHeight:0,
    
    searchCont:"",
    openmore:false,
    tabdex: "",
    popshow: false,
    paixuList:[
      { items: "回答次数", checked: false },
      { items: "处方次数", checked: false },
      { items: "响应时间", checked: false },
    ],
    shequList:[
      { items: "线上团队", checked: false },
      { items: "线下团队", checked: false },
    ],
    keshiList:[
      { items: "未解读", checked: false },
      { items: "已解读", checked: false },
    ],
    list:[],
    keyword:'',
    order:"",
    type:"",
    shequ:"",
    page:0,
    keshi:'',
    pagesize:10,
    shequ_arr:[],
    shequdex:0
  },
  shequclick(e){
    var id = e.currentTarget.dataset.id;
    var that = this;
    that.setData({
      shequdex:e.currentTarget.dataset.dex,
      page:0,
      list:[]
    })
    var keyword = that.data.keyword;
    var order = that.data.order;
    var type = that.data.type;
    var keshi = that.data.keshi;
    that.getList(id,order,type,keshi,keyword)
  },
  getSearch: function (e) {
    this.setData({
      keyword: e.detail.value
    })
  },
  // 搜索
  searchs:function(){
    var that = this;
    that.setData({
      page:0,
      list:[]
    })
    var keyword = that.data.keyword;
    var order = that.data.order;
    var type = that.data.type;
    var keshi = that.data.keshi;
    var shequ = that.data.shequ;
    that.getList(shequ,order,type,keshi,keyword)
  },
  hidepop(){
    this.setData({
      popshow: false,
      tabdex: ""
    })
  },
  tabbtn(e) {
    if (e.currentTarget.dataset.dex === this.data.tabdex) {
      this.setData({
        popshow: false,
        tabdex:"",
      })
    } else {
      wx.pageScrollTo({
        scrollTop: 100,
      })
      this.setData({
        popshow: true,
        tabdex: e.currentTarget.dataset.dex,
      })
    }
  },
  // 综合排序
  itemchecked1(e) {
    let arrs = this.data.paixuList, i = this.data.tabdex, dex = e.currentTarget.dataset.dex
    arrs.map(item => {
      item.checked = false
    })
    arrs[dex].checked = true
    this.setData({
      paixuList: arrs,
      popshow: false,
      tabdex: "",
      order:dex,
      paixuText:arrs[dex].items,
      page:0,
      list:[]
    })
    var that = this;
    var keyword = that.data.keyword;
    var shequ = that.data.shequ;
    var keshi = that.data.keshi;
    var type = that.data.type;
    that.getList(shequ,dex,type,keshi,keyword)
  },
  // 社区
  itemchecked2(e) {
    let arrs = this.data.shequList, i = this.data.tabdex, dex = e.currentTarget.dataset.dex
    arrs.map(item => {
      item.checked = false
    })
    arrs[dex].checked = true
    this.setData({
      shequList: arrs,
      popshow: false,
      tabdex: "",
      type:dex,
      shequText:arrs[dex].items,
      page:0,
      list:[]
    })
    var that = this;
    var keyword = that.data.keyword;
    var order = that.data.order;
    var keshi = that.data.keshi;
    var shequ = that.data.shequ;
    that.getList(shequ,order,dex,keshi,keyword);
  },
  // 科室
  itemchecked3(e) {
    let arrs = this.data.keshiList, i = this.data.tabdex, dex = e.currentTarget.dataset.dex;
    var id = e.currentTarget.dataset.id;
    arrs.map(item => {
      item.checked = false
    })
    arrs[dex].checked = true
    this.setData({
      keshiList: arrs,
      popshow: false,
      tabdex: "",
      keshi:id,
      keshiText:arrs[dex].ctname,
      page:0,
      list:[]
    })
    var that = this;
    var keyword = that.data.keyword;
    var order = that.data.order;
    var type = that.data.type;
    var shequ = that.data.shequ;
    that.getList(shequ,order,type,id,keyword);
  },
  openmore(){
    this.setData({
      openmore: !this.data.openmore
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
  var that = this;
  that.getShequ();
  that.getKeshi_arr();
  that.getList('','','','','');
  },
  // 获取社区列表
  getShequ:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/team.shequ",
      success:function(res){
        that.setData({
          shequ_arr:res.data
        })
      }
    })
  },
  // 获取科室列表
  getKeshi_arr:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/Team.keshi_one",
      success:function(res){
        that.setData({
          keshiList:res.data
        })
      }
    })
  },
  getList:function(shequ,order,type,keshi,keyword){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/team.lists",
      data:{
        keyword:keyword,
        order:order,
        type:type,
        shequ:shequ,
        keshi:keshi,
        page:that.data.page,
        pagesize:that.data.pagesize,
      },
      success:function(res){
        var page = that.data.page + 1;
        that.setData({
          list: that.data.list.concat(res.data),
          page: page
        });
      }
    })
  },
  onPageScroll(e){
    let h = e.scrollTop; let needFix = this.data.needFix; let bannerHeight = this.data.bannerHeight;
    if (h > 10 + bannerHeight){
      this.setData({
        needFix: true
      })
    } else if (h < 20){
      this.setData({
        needFix: false
      })
    }
    this.setData({
      bannerHeight:h
    })
  },
  doctoritem(e){
    var id = e.currentTarget.dataset.id;
    var title = e.currentTarget.dataset.title;
    wx.navigateTo({
      url: '/hyb_yl/doctor/pages/familydoctor/servercenter/servercenter?id='+id+'&title='+title
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var keyword = that.data.keyword;
    var order = that.data.order;
    var type = that.data.type;
    var keshi = that.data.keshi;
    var shequ = that.data.shequ;
    that.getList(shequ,order,type,keshi,keyword);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})